package io.gitee.zhangbinhub.acp.boot

import io.gitee.zhangbinhub.acp.boot.websocket.servlet.AcpWebSocketServerServlet
import org.springframework.boot.autoconfigure.AutoConfiguration
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
import org.springframework.web.socket.config.annotation.EnableWebSocket
import org.springframework.web.socket.config.annotation.WebSocketConfigurer
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry

@AutoConfiguration(after = [AcpComponentAutoConfiguration::class])
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@EnableWebSocket
class AcpWebSocketServletAutoConfiguration(private val acpWebSocketServerReactiveList: List<AcpWebSocketServerServlet>?) :
    WebSocketConfigurer {
    override fun registerWebSocketHandlers(registry: WebSocketHandlerRegistry) {
        acpWebSocketServerReactiveList?.forEach { item ->
            registry.addHandler(item, item.getPath())
        }
    }
}